package com.newland.starpos.project.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.newland.starpos.project.properties.OSSProperties;

@Configuration
@ConditionalOnClass({ OSSClient.class, OSSClientBuilder.class})
@EnableConfigurationProperties(OSSProperties.class)
public class OSSAutoConfiguration {
	
	@Autowired
	private OSSProperties OSSProperties;
	
	private ClientBuilderConfiguration config() {
		ClientBuilderConfiguration config = new ClientBuilderConfiguration();
		
		
		return config;
	}
	
	@Bean
	@ConditionalOnMissingBean(OSS.class)
	public OSS oss() {
		OSS ossclient = new OSSClientBuilder().build(OSSProperties.endpoint, 
				OSSProperties.accessKeyId, OSSProperties.accessKeySecret, config());
		
		
		
		return ossclient;
	}
	
}
